//turret.txt - Simple script for turrets
//Cell 0,1 - Stuff done flag. If both 0, nothing. Otherwise If non-zero, this 
//turret wont attack. If the turret is itself attacked, will set the not-attack setting back to 0.
//Cell 2,3 - Stuff done flag. If both 0, nothing. Otherwise when this is killed, set to 1.

begincreaturescript;

short i,target;
short last_abil;
short boom_count = 0;
short res = 0;

body;

beginstate INIT_STATE;
	set_name(ME,"Platano");
	set_level(ME,30);
	set_boss_level(ME,2);
	set_new_abil(ME,8);
	set_walk_speed(ME,0);
	
	place_particle_num(ME,18,12,4);		
	place_particle_num(ME,19,12,4);		
	place_particle_num(ME,20,12,4);		
	
	set_resistance(ME,5,100);
	last_abil = get_current_tick();
	break;

beginstate DEAD_STATE;
	sf(101,1,1);
break;

beginstate START_STATE; 
	if ((gf(73,16) > 0) && (res == 0)) {
		clean_off_particles(ME);
		set_resistance(ME,5,0);
		}
	if (who_shot_me() >= 0) {
		set_foe_target(ME,who_shot_me());
		do_attack();
		set_state(3);
		}

	if (get_foe_target(ME,8,0)) {
		do_attack();
		set_state(3);
		}
	if (am_i_doing_action() == FALSE)
		end_combat_turn();
break;

beginstate 3; // attacking
	if ((gf(73,16) > 0) && (res == 0)) {
		clean_off_particles(ME);
		set_resistance(ME,5,0);
		}

	if (target_ok() == FALSE)
		set_state(START_STATE);
	if (dist_to_char(get_target()) > 8) {
		set_foe_target(ME,-1);
		turret_heal();
		set_state(START_STATE);
		}
		
	if ((is_combat()) && 
	  (tick_difference(last_abil,get_current_tick()) > 0)) {
		last_abil = get_current_tick();
		boom_count = boom_count + 1;
		
		if (boom_count == 1) {
			print_str_color("The western pool is starting to bubble furiously.",3);
			run_sparkles_on_object(120,7,12,1);
			}
		if (boom_count == 2) 
			sf(73,19,1);
		if (boom_count == 3) {
			print_str_color("The eastern pool is starting to bubble furiously.",3);
			run_sparkles_on_object(121,7,12,1);
			}
		if (boom_count == 4) 
			sf(73,19,2);
			
		if (boom_count == 4)
			boom_count = 0;
		
		if (char_ok(50) == FALSE) {
			print_str_color("Platano casts a spell. A shade appears.",3);
			spawn_creature(42);
			run_char_animation(2,1,50);	
			pc_heard_sound_delay(136,100);						
				
			set_summon_level(50,1);
			place_particle_num(50,10,7,10);
			set_level(50,26);
			end();
			}
		}
	
		
	do_attack();

	turret_heal();
break;

beginstate TALKING_STATE;
	begin_talk_mode(110);
break;